package pkev.xgrapher.component;

import pkev.xgrapher.common.GrapherFactory;
import pkev.xgrapher.component.models.*;
import sun.java2d.SunGraphics2D;

import javax.swing.*;
import java.awt.*;

public class XGrapherPane extends JPanel {
    private GrapherFactory grapherFactory = null;

    public XGrapherPane() {
        super();
        grapherFactory = GrapherFactory.getInstance();
    }

    public XGrapherController getXGrapherController() {
        return grapherFactory.getXGrapherControllerInstance();
    }

    public void rePaint() {
        this.setVisible(false);
        this.setVisible(true);
    }


    @Override
    public void paint(Graphics g) {
        super.paint(g);
        ((SunGraphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        ((SunGraphics2D)g).setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        ((SunGraphics2D)g).setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        grapherFactory.getXGrapherControllerInstance().doPaint(g);
    }
}
